<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body class="list">
<div th:replace="include/head.html::html"></div>
<div class="layui-fluid layui-anim-upbit layui-anim">
    <div class="layui-card">
        <!--查询from 表单-->
        <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-hide">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <!--表格中的数据 并不显示-->
        <div class="layui-card-body">
            <!--表格外部上侧的按钮-->
            <div style="padding-bottom: 10px;" class="tool-bar">
                <button class="layui-btn add-btn" data-type="addLayer" shiro:hasPermission="CapitalFlow:add">添加</button>
            </div>
            <!--数据表格 -->
            <table id="table" lay-filter="table"></table>
            <!--表格每行的 的操作按钮 -->
            <script type="text/html" id="toolbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"
                   shiro:hasPermission="CapitalFlow:edit"><i
                        class="layui-icon layui-icon-edit"></i>修改</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
                   shiro:hasPermission="CapitalFlow:delbean"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="none">
    var table;
    layui.use(['jquery','table'], function () {
        table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#table'
            , id: 'table'
            , loading: true
            , method: 'post'
            , url: 'capitalFlow/page' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'numbers', title: '序号'}
                // , {field: 'userOid', title: '用户oid'}
                , {field: 'price', title: '金额'}
                , {field: 'isPay', title: '资金类型',templet:function (d) {
                    //1.支付订单 2.收入资金 3.提现  4退款 5退款退回
                        if(d.isPay == 1){
                            return "支付订单";
                        }else if(d.isPay == 2){
                            return "收入资金";
                        }else if(d.isPay == 3){
                            return "提现";
                        }else if(d.isPay == 4){
                            return "退款";
                        }else if(d.isPay == 5){
                            return "退款退回";
                        }
                    }}
                // , {field: 'otherOid', title: '关联oid'}
                , {field: 'createTime', title: '创建时间'}
                , {field: 'remarks', title: '备注'}
                , {title: '操作', width: 300, align: 'center', toolbar: '#toolbar'}
            ]]
        });
        //监听搜索
        form.on('submit(search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('table', {where: field});
        });
        //监听行工具事件
        //注：tool 是工具条事件名，table 是 table 原始容器的属性 lay-filter="对应的值"
        table.on('tool(table)', function (obj) {
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                editLayer({
                    title: '编辑',
                    url: 'CapitalFlow/edit?oid=' + data.oid,
                    area: ['50%', '80%'],
                    back: callback
                });
            } else if (layEvent === 'del') {
                layer.confirm('确定删除此行吗？', function (index) {
                    $.post("CapitalFlow/delBean", {oid: data.oid}, function (res) {
                        if (res.code === 0) {
                            layer.msg(res.msg);
                            table.reload('table');
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                });
            }
        });
        layui.$(".add-btn").on('click', function () {
            var type = layui.$(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var active = {
            addLayer: function () {
                var add = editLayer({
                    title: '添加',
                    url: 'CapitalFlow/edit',
                    area: ['50%', '80%'],
                    back: callback
                });
            }
        }
    });

    function callback(ifr, index, data) {
        var field = data.field;
        $.post("CapitalFlow/saveOrUpdate", field, function (res) {
            if (res.code === 0) {
                top.layer.msg(res.msg);
                top.layer.close(index);
                table.reload('table');
            } else {
                top.layer.msg(res.msg);
            }
        });
    }
</script>
</body>
</html>
